<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
	<base href="<%=basePath%>">
    
    <title></title>
	<%@ include file="/pages/mainPage/header.jsp" %>
  <style type="text/css">
  </style>
	</head>
	<body class="grayBg" id="corcenter_newl">
		<div>
			<input type="hidden" id="finalDiscountMoney" name="finalDiscountMoney">
			<input type="hidden" id="finalDeliverMoney" name="finalDeliverMoney">
			<input type="hidden" id="finalDiscountOrderNo" name="finalDiscountOrderNo">
			<input type="hidden" id="refundType" name="refundType">
			<input type="hidden" id="refundOrderNo" name="refundOrderNo">
			<input type="hidden" id="refundOrderDetailUuid" name="refundOrderDetailUuid">
			<input type="hidden" id="rejectReason" name="rejectReason">
		</div>
		<div style='padding-top:10px;width:100%;text-align:center;overflow:hidden;'>
	    	<div style='float:left;height: 30px;width:35%;height: 30px;text-align:right;'>
	    		<em>可提现金额（￥）：
	    	</div>
	    	<div style='float:left;height: 30px;width:60%;height: 30px;text-align:left;padding-left:10px;'>
	    		<em><c:out value='${agentMoney }'/><a style='padding-left:10px' href='javascript:void(0)' onclick="_setValue(<c:out value='${agentMoney }'/>)">提现全部金额</a></em>
	    	</div>
	    </div>
		<div style='padding-top:0px;width:100%;text-align:center;overflow:hidden;'>
	    	<div style='width:35%;float:left;text-align:right;height: 30px;'>银行卡号：</div>
	    	<div style='width:60%;float:left;height: 30px;line-height: 30px;text-align:left;padding-left:10px;'>
	    		<input type='text' id='bankAccount' name='bankAccount' value="<c:out value='${actualAmount.BANK_ACCOUNT }'/>" onchange="_checkBankAccount()" style="text-align:left;border: 1px solid #c7c7c7;height: 26px;width: 180px;" />
	    		<div id='bankAccountSpan' style='color:red;text-align: left;font-size: 14px;position: absolute;'></div>
	    	</div>
	    </div>
	    <div style='padding-top:20px;width:100%;text-align:center;overflow:hidden;'>
	    	<div style='width:35%;float:left;text-align:right;height: 30px;'>收款人姓名：</div>
	    	<div style='width:60%;float:left;height: 30px;text-align:left;padding-left:10px;'>
	    		<input type='text' id='bankAccountName' name='bankAccountName' value="<c:out value='${actualAmount.BANK_ACCOUNT_NAME }'/>" readonly style="text-align:left;border: 1px solid #c7c7c7;height: 26px;width: 180px;" />
	    		<div id='addPriceSpan' style='color:red;text-align: left;font-size: 14px;'></div>
	    	</div>
	    </div>
	    <div style='padding-top:20px;width:100%;text-align:center;overflow:hidden;'>
	    	<div style='width:35%;float:left;text-align:right;height: 30px;'>提现金额（￥）：</div>
	    	<div id='moneyId' style='width:60%;float:left;height: 30px;text-align:left;padding-left:10px;'>
	    		<input type='text' id='money' name='money' value="<c:out value='${agentMoney }'/>" onchange="_checkMoney()" style="text-align:right;border: 1px solid #c7c7c7;height: 26px;width: 180px;" />
	    	<div id='moneySpan' style='color:red;text-align: left;font-size: 14px;position: absolute;'></div></div>
    	</div>
    	<div style='padding-top:20px;width:100%;text-align:center;overflow:hidden;'>
	    	<div style='width:35%;float:left;text-align:right;height: 30px;'>提现手续费（￥）：</div>
	    	<div id='moneyFeeId' style='width:60%;float:left;height: 30px;text-align:left;padding-left:10px;'>
	    		<input type='text' id='moneyFee' name='moneyFee' value="<c:out value='${agentFee }'/>" readonly style="text-align:right;border: 1px solid #c7c7c7;height: 26px;width: 180px;" />
	    	</div>
    	</div>
    	<div style='padding-top:0px;width:100%;text-align:center;overflow:hidden;'>
	    	<div style='width:35%;float:left;text-align:right;height: 30px;'>实际到账金额（￥）：</div>
	    	<div id='realMoneyId' style='width:60%;float:left;height: 30px;text-align:left;padding-left:10px;'>
	    		<input type='text' id='realMoney' name='realMoney' value="" readonly style="text-align:right;border: 1px solid #c7c7c7;height: 26px;width: 180px;" />
	    	</div>
    	</div>
		<div style="padding-top:20px;width:100%;text-align:center;overflow:hidden;">
			<button id="queryBtn" class="orange_search_btn3" onclick="_tixianSubmit()" >确认提现</button>
		</div>
	</body>
	<script type="text/javascript">
  $(document).ready(function(){
		_checkBankAccount();
		_checkMoney();
  });
  function _tixianSubmit(){
  	if(!_checkBankAccount()){
  		layer.alert("银行卡号不符合规范");
  		return;
  	}
  	if(!_checkMoney()){
  		layer.alert("提现金额不符合要求");
  		return;
  	}
  	layer.open({
		content: '您确认提现吗？',
		btn: ['确认', '取消'],
		shadeClose: false,
		yes: function(){
			//layer.alert("正在建设中...");
			layer.closeAll();
			//return ;
			var bankAccount = $("#bankAccount").val();
			var bankAccountName = $("#bankAccountName").val();
			var money = $("#money").val();
			
			$.ajax({
		 		type:"GET",
				url:"<%=path%>/orderFee/agentPay.do",
				data: {
					money : money,
					bankAccount : bankAccount,
					bankAccountName : bankAccountName
				},
				dataType:"json",
				async : false, //同步执行
				success:function(data){
					if(data.success){
						layer.alert(data.msg);
						parent.layer.closeAll();
						$(window.parent.document).find("#rightFrame").attr("src","<%=path%>/orderFee/toOrderFeePage.do");
					} else {
						layer.alert(data.msg);
					}
				}
			});
		}, no: function(){
			
		}
	});
  }
  
  
  function _setValue(money){
  	$("#money").val(money.toFixed(2));
  }
  function _checkMoney(){
  	var result = false;
  	var money = $("#money").val();
  	var moneyFee = $("#moneyFee").val();
  	var agentMoney = "<c:out value='${agentMoney }'/>";
  	if(isNaN(money)){
  		$("#moneySpan").html("请输入正确金额");
  	} else if(parseFloat(money)<=0){
  		$("#moneySpan").html("请输入有效金额");
  	} else if(parseFloat(agentMoney)<parseFloat(money)){
  		$("#moneySpan").html("可提现金额不足");
  	} else if(parseFloat(money)<parseFloat(moneyFee)){
  		$("#moneySpan").html("提现金额需大于手续费");
  	} else {
  		result = true;
  		money = money*1.00;
  		$("#money").val(money.toFixed(2));
  		$("#moneySpan").html("");
  		//计算实际到账金额
  		var realMoney = parseFloat(money)-parseFloat(moneyFee);
  		$("#realMoney").val(realMoney.toFixed(2));
  	}
  	return result;
  }
  function _checkBankAccount(){
  	var result = false;
  	var bankAccount = $("#bankAccount").val();
  	var num = /^\d*$/; //全数字
  	if(bankAccount==""){
  		$("#bankAccountSpan").html("请输入银行卡号");
  	} else if(!num.exec(bankAccount)){
  		$("#bankAccountSpan").html("银行卡号只能为数字");
	} else if(bankAccount.length < 16 || bankAccount.length > 19){
  		$("#bankAccountSpan").html("银行卡号位数不正确");
  	} else {
  		result = true;
		var array = new Array();
		for(var i=1;i<=5;i++){
			if(bankAccount.length>0){
				var temp = bankAccount.substring(0,4);
				array.push(temp);
				bankAccount = bankAccount.substring(4,bankAccount.length);
			}
		}
		var bank_account = array.join(" ");
		$("#bankAccountSpan").css("color","#1887e7");
		$("#bankAccountSpan").html(bank_account);
	}
	return result;
  }
  </script>
</html>